package leetcode_周赛._2021._202104._20210411;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/4/11 11:00
 * 最少侧跳次数
 * 记录青蛙当前所在的跑道
 * 当前面有障碍时，怎么选择道路达到最小次数
 * 当遇到障碍时，看下一次的障碍出现在什么地方，只要不是重复跳两次即可
 * 当遇到障碍时，只有一条路可选
 */
public class _5728 {
    public static void main(String[] args) {
        String str = "yzh";
        StringBuilder sb = new StringBuilder(str);
    }
    public _5728() {
        return;
    }

    public int minSideJumps(int[] obstacles) {
        if (obstacles.length <= 2) return 0;
        int ans = 0, cur = 2;
        for (int i = 1; i < obstacles.length - 1; i++) {
            if (obstacles[i] == cur) {
                if (obstacles[i - 1] != 0) cur = 6 - cur - obstacles[i - 1];
                else {
                    int tem = obstacles[i];
                    for (i += 1; i < obstacles.length - 1; i++) {
                        if (obstacles[i] != 0 && obstacles[i] != tem) break;
                    }
                    cur = i < obstacles.length - 1 ? 6 - tem - obstacles[i] : 6 - tem;
                }
                ++ans;
            }
        }
        return ans;
    }
}
